const path = require('path');
const HTMLWebpackPlugin = require('html-webpack-plugin');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
module.exports = {

    //指定入口文件
    entry: "./src/index.ts",

    output: {
        //打包文件的目录
        path: path.resolve(__dirname,'dist'),
        //打包后文件的名字
        filename: "bundle.js",
        environment: {
            arrowFunction: false,
            const: false
        }
    },
    //指定打包时使用的文件
    module: {
        rules: [
            {
                //指定规则生效的文件
                test:/\.ts$/,

                //要使用的loader
                use:[
                    {
                        loader: "babel-loader",
                        options: {
                            //设置预定义的环境
                            presets:[
                                [
                                "@babel/preset-env",
                                //配置信息
                                {
                                    //要兼容的目标浏览器
                                    "targets":{
                                        "chrome":"88",
                                        "ie":"11"
                                    },
                                    //corejs指定的版本
                                    "corejs":"3",
                                    // 表示corejs按需加载
                                    "useBuiltIns":"usage",

                                }
                            ]
                            ]
                        }
                    },

                    'ts-loader'],

                //要排除的文件
                exclude: /node_moudles/
            },{
                test: /\.less$/,
                use: [
                    "style-loader",
                    "css-loader",
                    {
                        loader: "postcss-loader",
                        options: {
                            postcssOptions:{
                                plugins:[
                                    [
                                        "postcss-preset-env",
                                        {
                                            browsers:'last 3 versions'
                                        }
                                    ]
                                ]
                            }
                        }
                    },
                    "less-loader"
                ]
            }
        ]
    },
    plugins: [
        new CleanWebpackPlugin(),
        new HTMLWebpackPlugin({
            // title: "自定义title",
            template: "./src/index.html"
        }),

    ],
    resolve: {
        extensions: ['.js','.ts']
    }


}